package com.example.demo.controller.open;

import com.example.demo.common.lang.Result;
import com.example.demo.service.AnswersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * @author weihong
 * @date 2020/7/22 15:33
 */
@Api(tags = "问答核心")
@RestController
@RequestMapping("open/answers")
@Validated
public class AnswersController {

    private static final Logger log = LoggerFactory.getLogger(AnswersController.class);

    @Resource
    private AnswersService answersService;

    /**
     * 获取答案
     *
     * @param question
     * @return
     */
    @ApiOperation("获取答案")
    @GetMapping("getAnswers")
    public Result getAnswers(@RequestParam(value = "question") @NotBlank(message = "问题不能为空") String question) {
        log.info("获取答案入参：{}", question);
        String answer = answersService.getAnswer(question);
        log.info("输出答案：{}", answer);
        return Result.succ(answer);
    }
}
